
#include "epollserver.h"
#include <stdio.h>

#include "minishell_core.h"

extern int do_c1(void *ptr, int argc, char **argv);
extern int do_dlg_ask(void *ptr, int argc, char **argv);
extern int do_msg_append(void *ptr, int argc, char **argv);
// extern int do_msg_append(int argc, char **argv);
#ifdef __cplusplus
extern "C" {
#endif

// extern Dlg9x9 dialog;



struct cmd_prompt cmd_boot[] = {
	PROMPT_NODE(NULL, do_c1, "wndshow", NULL, NULL),
	PROMPT_NODE(NULL, do_dlg_ask, "ask", NULL, NULL),
	PROMPT_NODE(NULL, do_msg_append, "append", NULL, NULL),
	PROMPT_NODE(NULL, NULL, NULL, NULL, NULL),
	// 0,do_cl,"cmd",NULL,NULL
};
struct sh_detach_depth depth;





int epFUI_OnAccept(struct ep_t *pep, struct ep_con_t *pnode)
{
	// printf("----OnAccept----\n");
	return 0;
}

int epFUI_OnRecv(struct ep_t *pep, struct ep_con_t *pnode)
{
	// printf("----OnRecv----\n");
	int ret;
	char rbuf[1024];
	ret = recv(pnode->sockfd, rbuf, sizeof(rbuf)-1, 0);
	// printf("recv data :%s\n",rbuf);
	rbuf[ret] = '\0';
	// strcpy(rbuf,"append  1 2 3 4 5 6 7");
	sh_analyse_ex(rbuf,strlen(rbuf), &depth, pnode);
	// 返回值必须是recv函数的返回值
	return ret;
}

int epFUI_OnError(struct ep_t *pep, struct ep_con_t *pnode)
{
	// printf("----OnError----\n");
	return 0;
}

int epFUI_OnRemoveClose(struct ep_t *pep, struct ep_con_t *pnode)
{
	// printf("----OnRemoveClose----\n");
	return 0;
}

int epFUI_OnConnect(struct ep_t *pep, struct ep_con_t *pnode)
{
	// printf("----epFUI_OnConnect----\n");
	return 0;
}
int epFUI_OnRelease(struct ep_t *pep)
{
	// printf("----epFUI_OnRelease----\n");
	return 0;
}
int epFUI_OnClose(struct ep_t *pep, struct ep_con_t *pnode)
{
	// printf("----epFUI_OnClose----\n");
	return 0;
}






void ep_Callback(struct ep_t *pep)
{

	sh_whereboot(cmd_boot);
	// funtest();
	// initialize_readline();
	
	char *cmd[12];

	depth.cmd = cmd;
	depth.len = 12;
	depth.seps = " \t";

	char buf[30];
	// strcpy(buf,"append  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15");
	// sh_analyse_ex(buf,strlen(buf), &depth, NULL);

	// sh_enter_ex(&depth, NULL);


	pep->pFUI_OnAccept      = epFUI_OnAccept;
	pep->pFUI_OnConnect     = epFUI_OnConnect;
	pep->pFUI_OnRecv        = epFUI_OnRecv;
	pep->pFUI_OnError       = epFUI_OnError;
	pep->pFUI_OnRemoveClose = epFUI_OnRemoveClose;
	pep->pFUI_OnRelease     = epFUI_OnRelease;
	pep->pFUI_Close         = epFUI_OnClose;
}

#ifdef __cplusplus
}
#endif

